package za.ac.nmmu.muhelp.data;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import java.util.List;
import java.util.logging.Logger;

import za.ac.nmmu.muhelp.model.Configuration;

@ApplicationScoped
public class ConfigurationRepository {

    @Inject
    private EntityManager em;

    @Inject
    private Logger log;

    //
    // only expecting one live entry
    //
    public Configuration findLive() {
	String query = 
		"select c from za.ac.nmmu.muhelp.model.Configuration as c where live = 't'";
	log.info("query is [" + query + "]");
	List<Configuration> configurations = (List<Configuration>) em.createQuery(query).getResultList();
	return configurations.get(0);
    }

    
}
